<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>listBooks</title>
</head>
<body>

<center>
    <h3>导入exl文件数据</h3>
    <form enctype="multipart/form-data" id="fileForm" action="importFileData"  method="post" >
        <table class="table">
            <tr>
                <td>Exl文件</td>
                <td>
                    <!--<input type="file" name="file" id="importFile" onchange="importFileS()">-->
                    <input type="file" accept=".xls,.xlsx" id="exlFile" name="file" >
                </td>
                <td>
                    <input type="button" onclick="importFileS()" value="导入">
                </td>
            </tr>
        </table>
    </form>

</center>
<script th:src="@{js/jquery-2.1.4.min.js}"></script>
<script th:inline="javascript">


    function importFileS(){
        var files = $("#exlFile").get(0).files[0]; //获取file控件中的内容
        // var form = $("#fileForm").serialize();
        var formData = new FormData();
        formData.append("file", files);
        $.ajax({
            type:"POST",
            url:"importFileData",//接口请求地址
            data:formData,
            dataType:'json',
            processData : false, // 使数据不做处理
            contentType : false, // 不要设置Content-Type请求头
            success:function(data){
                console.log(data);
            }
        });
    }
</script>
</body>
</html>
